import { request } from "umi";


// 获取数据

interface IOptions {
  [params:string]:string;
}
interface ISearchParams {
  page:number;
  options: IOptions
}

export function getKnowledgeList(params:ISearchParams,pageSize:number=12) {
  let str = '';
  for(let key in params.options){
      if(params.options[key]){
          str = str + '&' + key + '=' + params.options[key];
      }
  }  
  return request(`/api/knowledge?page=${params.page}&pageSize=${pageSize}${str}`);
}

// 删除
export const delKnowledgeList = (params:string) => {
    return request(`/api/knowledge/${params}`,{
        method:'DELETE'        
    })
    
}

// 发布设为草稿
interface IParams {
  [propsName:string]:string
}
export function publishOrDrafs(params:IParams) {
  return request(`/api/knowledge/${params.id}`, {
      method: "PATCH",
      data: {
        status:params.status
      },
  })
}
// 获取抽屉内盒子的文件上传图混合数据

export function getKnowledgeDrawerList(page: number = 1,pageSize:number=12) {
  let params = {
    page,
    pageSize: 12,
  }
  return request('/api/file', {
    params
  });
}

// 创建知识小册
interface createType {
  [props:string]:string
}
export function createKnowledgeList(payload:createType){
  return request('/api/knowledge/book',{
    method:'POST',
    data:payload
  })
}

// 更新知识小册
export function updateKnowledgeList(payload:createType){
  console.log('aaaaaaa',payload)
  return request(`/api/knowledge/${payload.id}`,{
    method:'PATCH',
    data:{
      cover:payload.cover,
      isCommentable:payload.isCommentable,
      summary:payload.summary,
      title:payload.title
    }
  })
}